package com.yunji.system.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import org.springframework.context.annotation.Bean;

//@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        return new MybatisPlusInterceptor();
    }
//    @Autowired
//    private Environment env;

//    @Autowired
//    private MybatisSqlSessionFactoryBean sessionFactoryBean;

//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//        final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
//        sessionFactory.setPlugins(mybatisInterceptor);
//        sessionFactory.setDataSource(dataSource);
//        sessionFactory.setTypeAliasesPackage(Objects.requireNonNull(env.getProperty("mybatis-plus.typeAliasesPackage")));
//        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(Objects.requireNonNull(env.getProperty("mybatis-plus.configLocation"))));
//        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//        sessionFactory.setMapperLocations(resolver.getResources(Objects.requireNonNull(env.getProperty("mybatis-plus.mapperLocations"))));
//        //sessionFactory.setMapperLocations(resolveMapperLocations(mybatisPlusProperties.getMapperLocations()));
//        return sessionFactoryBean.getObject();
//    }

    //    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor(){
//        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
//        paginationInnerInterceptor.setMaxLimit(-1L);
//        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
//        return new MybatisPlusInterceptor();
//    }

//    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor() {
//        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
//        return mybatisPlusInterceptor;
//    }

//    @Bean
//    PageInterceptor pageInterceptor() {
//        PageInterceptor pageInterceptor = new PageInterceptor();
//        Properties properties = new Properties();
//        properties.setProperty("helperDialect", "mysql");
//        pageInterceptor.setProperties(properties);
//        return pageInterceptor;
//    }
}
